while true do
 write("Username: ")
 local input = read()
 if fs.exists("/etc/passwd/"..input..".dat") and not fs.isDir("/etc/passwd/"..input..".dat") then
  local pass = security.unpassbyte(input)
  while true do
   if kernel.secureInput("Password:", pass) then
    os.pullEvent = function()
	 local eventData = { os.pullEventRaw( _sFilter ) }
	 if eventData[1] == "terminate" then
	  error( "Terminated", 0 )
	 end
	 return unpack( eventData )
	end
    kernel.clear()
	rawset(_G, "_activeUser", input)
	if fs.exists("/home/".._G["_activeUser"].."/autorun") then
	 shell.run("/home/".._G["_activeUser"].."/autorun")
	end
	log.writeAuth("User "..input.." logged in")
	if input == "root" then
	 log.writeSecurity("Superuser account is active")
	end
    shell.run("/bin/sh")
	if security.getSU() then
     gui.printAppWarning("kernel", "exiting into top-level shell")
     log.writeMessage("exiting into top-level shell")
	 break
	end
	kernel.shutdown(false)
   end
  end
 end
 if input == "root" and security.getSU() then
  break
 end
end